package com.taxshare.operation;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.spring.web.SpringfoxWebMvcConfiguration;

import javax.servlet.MultipartConfigElement;

@ConditionalOnClass(SpringfoxWebMvcConfiguration.class)
@SpringBootApplication
@ComponentScan("com.taxshare")
@EnableFeignClients
@MapperScan(basePackages = { "com.taxshare.operation.mapper"})
@Slf4j
public class OperationApplication implements WebMvcConfigurer {

	public static void main(String[] args) {
		SpringApplication.run(OperationApplication.class, args);
		log.error(">>>>>>>>>Operation完美启动>>>>>>>>");
	}
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
	}

	@Bean
	public MultipartConfigElement multipartConfigElement() {
		MultipartConfigFactory factory = new MultipartConfigFactory();
		//文件最大KB,MB
		factory.setMaxFileSize(DataSize.of(20, DataUnit.MEGABYTES));
		//设置总上传数据总大小
		factory.setMaxRequestSize(DataSize.of(20, DataUnit.MEGABYTES));
		//设置默认路径
		factory.setLocation("/tmp");
		return factory.createMultipartConfig();
	}
}
